<extend name="common:commonTemplate"/>
<block name="main_content">
    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a class="tip-bottom" href="index.html"
                   data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
                <a href="#">推广人</a> <a class="current" href="#">产品信息列表</a>
            </div>

        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
                            <h5>搜索条件</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <form novalidate="novalidate" id="basic_validate"
                                  name="basic_validate" action="#" method="post"
                                  class="form-horizontal">
                                <div class="control-group">
                                    <label class="control-label">物料编号</label>
                                    <div class="controls">
                                        <input type="text" name="material_no">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">物料名称</label>
                                    <div class="controls">
                                        <input type="text" name="product_name">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">69编码</label>
                                    <div class="controls">
                                        <input type="text" name="69_code">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">海尔物料编号</label>
                                    <div class="controls">
                                        <input type="text" name="haier_material_no">
                                    </div>
                                </div>
                                <div class="form-actions">
                                    <input id="btn_search" type="button" class="btn btn-success" value="搜索">
                                    <a style="background:red" class="btn btn-success"
                                       href="/product/addProductPage">新增</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title"><span class="icon"> <i class="icon-th"></i> </span>
                            <h5>搜索结果</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <table id="search_result" page_index="1" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>物料编号</th>
                                    <th>物料名称</th>
                                    <th>产品型号</th>
                                    <th>69编码</th>
                                    <th>海尔物料编号</th>
                                    <th>成本价</th>
                                    <th>产品分类</th>
                                    <th>产品大类</th>
                                    <th>分辨率</th>
                                    <th>备件小类</th>
                                    <th>备件厂商</th>
                                    <th>备件机型</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div id="paging"
                         class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
                        <div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers"
                             id="DataTables_Table_0_paginate">
                            <a page_index="1"
                               class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_first">首页</a>
                            <a class="previous fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_previous">上页</a>
                            <span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span
                                    id="total_page">0</span></span>
                            <a class="next fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_next">下页</a>
                            <a class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_last">末页</a>
       			<span>
        			<span><input type="text" style="width:20px;" class="ui-state-default" id="jump_num"></span>

        			<a class="fg-button ui-button ui-state-default" id="DataTables_Table_jump" tabindex="0">跳转</a>
       			</span>
                        </div>
                    </div>


                </div>
            </div>

        </div>


    </div>
</block>

<block name="js_content">
    <script>
        ProductPage = {
            'BindEvent': function () {
                $('#btn_search').bind('click', function () {
                    var page_index = 1;
                    ProductPage.Search(page_index);
                });
                
                $('#DataTables_Table_jump').bind('click',function(){
					var page_index =  $('#jump_num').val();
					if(!isNaN(page_index)){
						ProductPage.Search(page_index);
					}else{
					   alert("跳转必须页必须为数字");
					}
				});

                $(".first,.previous,.last,.next").bind('click', function () {
                    if ($(this).hasClass('ui-state-disabled')) {
                        return false;
                    }

                    var page_index = $(this).attr('page_index');
                    if (page_index == undefined) {
                        page_index = 1;
                    }
                    //page_index = 1;
                    ProductPage.Search(page_index);
                });
            },
            'Search': function (page_index) {
                var condition = $("#basic_validate").serialize();

                condition += "&pageSize=20&index=" + page_index;

                $.ajax({
                    type: 'post',
                    url: '/AjaxService/center/product/queryProduct',
                    data: condition,
                    dataType: 'json',
                    async: false,
                    success: function (data) {
                        ProductPage.FillTable(data.Result, page_index);
                        ProductPage.SetPageIndex(data.Result.totalPage, data.Result.totalCount, page_index);


                    },
                    error: function (e, err_name, err_text) {
                        alert(err_text);
                    }
                });

            },
            'convertNull': function (str) {
                if (str) return str;
                return "";
            },
            'FillTable': function (result, page_index) {
                lst_product_en = result.datas;

                var html = '';
                if (lst_product_en.length > 0) {
                    for (var index in lst_product_en) {
                        var product = lst_product_en[index];
                        var tr_html = "<tr>";
                        tr_html += "<td>" + ProductPage.convertNull(product.material_no) + "<br /></td>";
                        tr_html += "<td>" + ProductPage.convertNull(product.product_name) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.material_desc) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.six_code) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.haier_material_no) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.cost_price) + "</td>"
                        tr_html += "<td>" + ProductPage.product_type_test(product.product_type) + "</td>"
                        tr_html += "<td>" + ProductPage.product_group_test(product.product_group) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.product_resolving) + "</td>"
                        tr_html += "<td>" + ProductPage.product_part_group_test(product.product_part_group) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.part_work_shop) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.product_part_model) + "</td>"
                        tr_html += "<td>" + ProductPage.status_test(product.status)+ "</td>"
                        tr_html += '<td><div style="text-align:center;"><a style="color:blue;" href="/product/editproductPage?product_id=' + product.product_id + '">查看详情</a></div></td>';
                        tr_html += "</tr>";
                        html += tr_html;
                    }
                } else {
                    html = '<td style="text-align:center" colspan="10">没查到数据</td>'
                }


                $('#search_result tbody').html('');
                $('#search_result tbody').html(html);

                $('#search_result').attr('page_index', page_index);
            },
            'SetPageIndex': function (total_page, total_count, page_index) {
                $('#total_count').text(total_count);
                $('#total_page').text(total_page);
                $('#curr_page_index').text(page_index);
                page_index = parseInt(page_index);
                total_count =parseInt(total_count);
				
				if(total_page == 0){
					$('#paging .last').addClass('ui-state-disabled');
					$('#paging .next').addClass('ui-state-disabled');
					$('#paging .first').addClass('ui-state-disabled');
					$('#paging .previous').addClass('ui-state-disabled');
					return;
				}
                if (page_index == 1) {
                    $('#paging .first').addClass('ui-state-disabled');
                    $('#paging .previous').addClass('ui-state-disabled');
                    $('#paging .first').attr('page_index', 1);
                    $('#paging .previous').attr('page_index', 1);
                }
                else {
                    $('#paging .first').removeClass('ui-state-disabled');
                    $('#paging .previous').removeClass('ui-state-disabled');
                    $('#paging .first').attr('page_index', 1);
                    $('#paging .previous').attr('page_index', page_index - 1);
                }

                if (total_page == page_index) {
                    $('#paging .last').addClass('ui-state-disabled');
                    $('#paging .next').addClass('ui-state-disabled');
                    $('#paging .last').attr('page_index', total_page);
                    $('#paging .next').attr('page_index', total_page);
                }
                else {
                    $('#paging .last').removeClass('ui-state-disabled');
                    $('#paging .next').removeClass('ui-state-disabled');
                    $('#paging .last').attr('page_index', total_page);
                    $('#paging .next').attr('page_index', page_index + 1);
                }

            },
            'status_test':function(obj){
    			if(obj == '0'){
    				return '无效';
    			}else if(obj =='1'){
    				return '有效';
    			}
    		} ,
            'product_type_test':function(obj){
    			if(obj == '1'){
    				return '成品';
    			}else if(obj =='2'){
    				return '备件';
    			}else if(obj =='3'){
    				return '配件';
    			}else{
    				return '';
    			}
    		} ,
    		'product_group_test':function(obj){
    			if(obj == '1'){
    				return 'TV';
    			}else if(obj =='2'){
    				return '微投';
    			}else if(obj =='3'){
    				return 'VR';
    			}else if(obj =='4'){
    				return '音响';
    			}else{
    				return '';
    			}
    		} ,
    		'product_part_group_test':function(obj){
    			if(obj == '1'){
    				return '电源板';
    			}else if(obj =='2'){
    				return '主板';
    			}else if(obj =='3'){
    				return '标签';
    			}else if(obj =='4'){
    				return '纸箱';
    			}else if(obj =='5'){
    				return '泡沫';
    			}else if(obj =='6'){
    				return '说明书';
    			}else if(obj =='7'){
    				return '螺丝';
    			}else if(obj =='8'){
    				return '电池';
    			}else if(obj =='9'){
    				return '线材';
    			}else if(obj =='10'){
    				return '底座';
    			}else if(obj =='11'){
    				return '机壳';
    			}else if(obj =='12'){
    				return '卡扣';
    			}else if(obj =='13'){
    				return '整机PE袋';
    			}else if(obj =='14'){
    				return '打包带';
    			}else if(obj =='15'){
    				return '内六角扳手';
    			}else if(obj =='16'){
    				return '封箱胶带';
    			}else if(obj =='17'){
    				return 'WIFI天线';
    			}else if(obj =='18'){
    				return 'LCM模组';
    			}else if(obj =='19'){
    				return '喇叭';
    			}else if(obj =='20'){
    				return '遥控器';
    			}else if(obj =='21'){
    				return '脚垫';
    			}else if(obj =='22'){
    				return 'WIFI板';
    			}else if(obj =='23'){
    				return 'KEY板';
    			}else if(obj =='24'){
    				return 'TCON板';
    			}else if(obj =='25'){
    				return 'IR板';
    			}else if(obj =='26'){
    				return '开关';
    			}else{
    				return '';
    			}
    		} ,
    		
        };


        $(document).ready(function () {
            ProductPage.BindEvent();
        });
    </script>
</block>